package com.yzh.exception3;

/**
 * @author 于振晗
 * @title: Person
 * @description: TODO
 * @date 2020年08月29日
 * @path com.yzh.exception3
 */
public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age<0 || age>130){
            throw new AgeException("年龄越界");
        }else{
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
